module EventEditor
  module Route
    class Move
    @types = [
        ['Up', 'up'], 
        ['Right', 'right'], 
        ['Down', 'down'], 
        ['Left', 'left'], 
        ['UpperLeft', 'upper_left'], 
        ['UpperRight', 'upper_right'], 
        ['BottomLeft', 'bottom_left'], 
        ['BottomRight', 'bottom_right'],
        ['+90', 'rotate_right'],
        ['-90', 'rotate_left'],
        ['+180', 'flip'],
        ['Against', 'against'],
        ['To', 'to'],
        ['Forward', 'forward'],
        ['Backward', 'backward'],
        ['Random', 'random']
        ]
        
      @type_names = {
        'up' => 'Up',
        'right' => 'Right',
        'down' => 'Down',
        'left' => 'Left',
        'upper_left' => 'UpperLeft', 
        'upper_right' => 'UpperRight',
        'bottom_left' => 'BottomLeft', 
        'bottom_right' => 'BottomRight',
        'rotate_right' => '+90',
        'rotate_left' => '-90',
        'flip' => '+180',
        'against' => 'Against',
        'to' => 'To',
        'forward' => 'Forward',
        'backward' => 'Backward',
        'random' => 'Random'
        }
        
     def self.show(base, &func)
        dialog = Gtk::Dialog.new("Move Dialog",
               base,
               Gtk::Dialog::MODAL |
               Gtk::Dialog::DESTROY_WITH_PARENT,
               ["OK", Gtk::Dialog::RESPONSE_OK],
               ["Cancel", Gtk::Dialog::RESPONSE_CANCEL]
               )

        dialog.vbox.add(self.create_panel)
        dialog.vbox.show_all

        # run
        dialog.run do |response|
          if response == Gtk::Dialog::RESPONSE_OK
            func.call(self.command)
          else
            func.call(:cancel)
          end
          dialog.destroy
        end
      end

      def self.create_panel
        vbox = Gtk::VBox.new
        vbox.add(@type_combobox = ::Gadgets::Combobox.new(@types, [String, String]))
        vbox.add(@amount_input = Gtk::SpinButton.new(0, 99, 1))

        return vbox
      end
      
      def self.command
        ['move', @type_combobox.selected_data, @amount_input.value.floor]
      end
      
      def self.command_to_s(args)
        if args[2] == 0
          return "Face: #{@type_names[args[1]]}"
        else
          return "Move: #{@type_names[args[1]]} x #{args[2]}"
        end
      end
    end
  end
end